package com.books.model;

import com.books.enums.ResultCodeEnum;
import lombok.Data;

@Data
public class Result <T>{
    private ResultCodeEnum code;
    private String errMsg;
    private T data;

    public static<T> Result success(T data){
        Result result=new Result();
        result.setCode(ResultCodeEnum.SUCCESS);
        result.setData(data);
        result.setErrMsg("");
        return result;
    }


    public static<T> Result fail(T data,String errMsg){
        Result result=new Result();
        result.setCode(ResultCodeEnum.FAIL);
        result.setData(data);
        result.setErrMsg(errMsg);
        return result;
    }

    public static<T> Result fail(String errMsg){
        Result result=new Result();
        result.setCode(ResultCodeEnum.FAIL);
        result.setData(null);
        result.setErrMsg(errMsg);
        return result;
    }

    public static<T> Result unlogin(String errMsg){
        Result result=new Result();
        result.setCode(ResultCodeEnum.UNLOGIN);
        result.setData(null);
        result.setErrMsg(errMsg);
        return result;
    }
}
